package core

import (
	"fmt"
	"sync"
	"time"
)

type Log struct {
	LogBus chan string
}

var (
	instance1 *Log
	once1     sync.Once
)

const ( // DEBUG -> INFO -> WARN -> ERROR -> FATAL
	Log_Debug = "Debug"
	Log_Info  = "Info"
	Log_Warn  = "Warn"
	Log_Error = "Error"
	Log_Fatal = "Fatal"
)

func GetLog() *Log {
	once1.Do(func() {
		// 数据总线，用于应用间通信
		instance1 = &Log{LogBus: make(chan string, 100)}
	})
	return instance1
}

func (log *Log) ShowMsg(log_level string, a ...any) {
	buf := fmt.Sprintln("["+time.Now().Format(time.DateTime)+"]["+log_level+"]", a)
	log.LogBus <- buf
}
